package com.info.dpunified.dpgen.dataaccess;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;
import com.info.dpunified.dpgen.domain.RadarDefect;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class RadarDefectDAO  {


	protected final Log logger = LogFactory.getLog(getClass());
	
	private JdbcTemplate jdbcTemplate;

	/**
	 * Specify the statement
	 */
	private static final String INSERT_DEFECT_QUERY = "INSERT INTO DPURadarDefect VALUES " +
			"(?,?,?,?,?,?,?,?,?,?," +
			" ?,?,?,?,?,?,?,?,?,?," +
			" ?,?,?,?,?,?,?,?,?,?," +
			" ?,?,?,?,?,?,?,?,?,?," +
			" ?,?,?,?,?,?,?,?,?,?," +
			" ?,?,?,?,?,?,?,?,?)";

	
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	public void insertDefect(RadarDefect radarDefect) {

		/**
		 * Specify the values
		 */
		jdbcTemplate.update(INSERT_DEFECT_QUERY, (Object[]) radarDefect.getInsertValues());
	}
	
	public void insertDefects(List<RadarDefect> radarDefectList) {
		for(RadarDefect radarDefect : radarDefectList)
		{
			logger.info("Adding defect to central repository with Defect Id ["+radarDefect.getDefectID()+"]");
			this.insertDefect(radarDefect);
		}
	}
	
}